//
//  MapTopView.m
//  sanmuBoom
//
//  Created by 杨森 on 2017/5/13.
//  Copyright © 2017年 sanmu. All rights reserved.
//

#import "MapTopView.h"
#define topH 50
#define ViewW 60


@interface MapTopView()

@property(nonatomic,strong)NSMutableArray *btnArray;
@property(nonatomic,strong)UIButton *selectBtn;

@end

@implementation MapTopView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self buildToolView];
    }
    return self;
}

- (NSDictionary *)tools
{
    return @{
             @"map_car"  :@"map_car_s",
             @"map_bus"  :@"map_bus_s",
             @"map_walk" :@"map_walk_s"
             };
}

- (void)buildToolView
{
    for (int i = 0; i < self.tools.allKeys.count; ++i) {
        
        UIButton *button = [[UIButton alloc] init];
        [button setImage:[UIImage imageNamed:self.tools.allKeys[i]] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:self.tools.allValues[i]] forState:UIControlStateSelected];
        [button setTitle:@"暂无信息" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [button setTitleColor:RGBA(74,116,251,1) forState:UIControlStateSelected];
        button.titleLabel.font = FONT(10);
        
        button.tag = i;
        [self.btnArray addObject:button];
        [self addSubview:button];
        
        button.imageEdgeInsets = UIEdgeInsetsMake(-20,15,0,0);
        button.titleEdgeInsets = UIEdgeInsetsMake(30,-20,0,0);

        WeakSelf(self);
        if (i == 1) {
            
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.equalTo(weakself);
                make.height.mas_equalTo(topH);
                make.width.mas_equalTo(ViewW);
            }];
        }else if (i == 0){
            
            button.selected = true;
            self.selectBtn = button;

            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(weakself);
                make.centerX.equalTo(weakself).offset(-100);
                make.height.mas_equalTo(topH);
                make.width.mas_equalTo(ViewW);
            }];
        }else{
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(weakself);
                make.centerX.equalTo(weakself).offset(100);
                make.height.mas_equalTo(topH);
                make.width.mas_equalTo(ViewW);
            }];
        }
        
        [button addTarget:self action:@selector(toolBtnclick:) forControlEvents:UIControlEventTouchUpInside];
    }
}

- (void)toolBtnclick:(UIButton *)button
{
    self.selectBtn.selected = false;
    button.selected = true;
    self.selectBtn = button;
    
    if (self.topBlock) {
        self.topBlock(button.tag);
    }
}




@end
